import {ActionTree, Module} from 'vuex'
import {FilterableBundleState, RootState} from '../types'
import {url} from '@/store/utils'
import {AxiosPromise} from 'axios'
const namespaced: boolean = true

const actions: ActionTree<FilterableBundleState, RootState> = {
  list(context, payload) {
    return axios.post(url(`/api/filterable-bundle/list`), payload)
  },
  add(context, payload) {
    return axios.post(url(`/api/filterable-bundle/add`), payload)
  },
  delete(context, id){
    return axios.delete(url(`/api/filterable-bundle/delete/${id}`))
  },
  update(context, payload) {
    return axios.post(url(`/api/filterable-bundle/update/${payload.id}`), payload)
  },
  listCriteria(context, payload) {
    let {id, data} = payload
    return axios.post(url(`/api/filterable-bundle/criteria/list/${id}`), data)
  },
  addCriterion(context, payload): AxiosPromise{
    let {id, data} = payload
    return axios.post(url(`/api/filterable-bundle/criteria/add/${id}`), data)
  },
  listCriterionFilterResult(context, payload): AxiosPromise {
    let {id, data} = payload
    return axios.post(url(`/api/filterable-bundle/criterion/filter/${id}`), data)
  },
  delItemByIds(context, payload): AxiosPromise{
    return axios.post(url(`/api/filterable-bundle/criteria/del-by-ids`), payload)
  }
}

export const FilterableBundleStore: Module<FilterableBundleState, RootState> = {
  namespaced,
  actions
}

export default FilterableBundleStore